﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SA = System.Array;

namespace Awesome.Extensions.Array
{
    public static class ArrayEx
    {
        /// <summary>
        /// Returns element at index or dafault.
        /// </summary>
        public static T ElementAtOrDefault<T>(this T[] array, int index)
        {
            return 0 <= index && index < array.Length ? array[index] : default(T);
        }


        /// <summary>
        /// Create copy of array.
        /// </summary>
        public static T[] Copy<T>(this T[] array)
        {
            var newArray = new T[array.Length];
            array.CopyTo(newArray, 0);

            return newArray;
        }

        /// <summary>
        /// Returns index of element or -1 of search fails.
        /// </summary>
        public static int IndexOf<T>(this T[] array, T element)
        {
            return SA.IndexOf(array, element);
        }
    }
}
